package presentation.menuForm_UI;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;

import business.menuForm_Evt.MenuForm_Evt;

public class MenuForm_UI {

        public static JFrame frame = new JFrame();
        private JPanel panelButton = new JPanel();
        private Picture pic = new Picture();
        private JButton btPlayGame = new JButton("");
        private JButton btOption = new JButton("");
        private JButton btHelp = new JButton("");
        private JButton btExit = new JButton("");
        private MenuForm_Evt event = new MenuForm_Evt(frame);

        public MenuForm_UI() {
                initComponents();
        }

        private void initComponents() {
                frame.setSize(800, 600);
                frame.setVisible(true);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLocationRelativeTo(null);
                frame.setResizable(false);
                frame.setTitle("Find Word Game");

                setMainLayout();
                btPlayGame.requestFocus();

               frame.setIconImage(Toolkit.getDefaultToolkit().getImage("src/Image/icon.png"));
                
                buttonEvent();
                picPanelEvent();
                keyEvent();
        }

        private void setMainLayout() {

                setPanelButtonLayout();
                frame.setLayout(null);
                frame.add(panelButton);
                panelButton.setBounds(0, 0, 800,600);
        }

        private void setPanelButtonLayout() {
                setButtons();
                panelButton.setPreferredSize(new Dimension(800, 600));
                panelButton.setLayout(null);
                panelButton.add(pic);
              
                pic.setBounds(0, 0, 800, 600);
                pic.setOpaque(false);
                

                panelButton.add(btPlayGame);
                panelButton.add(btOption);
                panelButton.add(btHelp);
                panelButton.add(btExit);

                btPlayGame.setBounds(0, 0, 10, 10);
                btOption.setBounds(10, 10, 10, 10);
                btPlayGame.setBounds(20, 20, 10, 10);
                btOption.setBounds(30, 30, 10, 10);
        }

        private void setButtons() {
                this.btPlayGame.requestFocus();
                this.btPlayGame.setOpaque(false);
                this.btPlayGame.setBorderPainted(false);
                this.btPlayGame.setContentAreaFilled(false);

                this.btOption.setContentAreaFilled(false);
                this.btOption.setBorderPainted(false);
                this.btOption.setContentAreaFilled(false);

                this.btHelp.setContentAreaFilled(false);
                this.btHelp.setBorderPainted(false);
                this.btHelp.setContentAreaFilled(false);

                this.btExit.setContentAreaFilled(false);
                this.btExit.setBorderPainted(false);
                this.btExit.setContentAreaFilled(false);

        }

        public static void main(String[] args) {
                try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (Exception ex) {
                        ex.printStackTrace();
                }
                new Window().setVisible(true);
        }

        private void buttonEvent() {
                btPlayGame.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                                event.playMouse_Preesed();
                                event.showPlay();
                        }
                });

                btOption.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                                event.playMouse_Preesed();
                                event.showOption();
                        }
                });

                btHelp.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                                event.playMouse_Preesed();
                                event.showHelp();
                        }
                });

                btExit.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                                event.playMouse_Preesed();
                                event.btExit_Event();
                        }
                });


        }

        private void keyEvent() {
                btPlayGame.addKeyListener(new KeyAdapter() {

                        @Override
                        public void keyPressed(KeyEvent evt) {
                                if (evt.getKeyCode() == KeyEvent.VK_UP) {
                                        btExit.requestFocus();
                                        pic.path = "src/Image/focuesed_exit.png";
                                        pic.repaint();
                                       //event.playMouse_Over();
                                }
                                if (evt.getKeyCode() == KeyEvent.VK_LEFT) {
                                        btExit.requestFocus();
                                        pic.path = "src/Image/focuesed_exit.png";
                                        pic.repaint();
                                        //event.playMouse_Over();
                                }

                                if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
                                        btOption.requestFocus();
                                        pic.path = "src/Image/focuesed_option.png";
                                        pic.repaint();
                                        //event.playMouse_Over();
                                }
                                if (evt.getKeyCode() == KeyEvent.VK_RIGHT) {
                                        btOption.requestFocus();
                                        pic.path = "src/Image/focuesed_option.png";
                                        pic.repaint();
                                        //event.playMouse_Over();
                                }
                        }
                });

                btOption.addKeyListener(new KeyAdapter() {

                        @Override
                        public void keyPressed(KeyEvent evt) {
                                if (evt.getKeyCode() == KeyEvent.VK_UP) {
                                        btPlayGame.requestFocus();
                                        pic.path = "src/Image/focuesed_playgame.png";
                                        pic.repaint();
                                        //event.playMouse_Over();
                                }
                                if (evt.getKeyCode() == KeyEvent.VK_LEFT) {
                                        btPlayGame.requestFocus();
                                        pic.path = "src/Image/focuesed_playgame.png";
                                        pic.repaint();
                                        //event.playMouse_Over();
                                }
                                if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
                                        btHelp.requestFocus();
                                        pic.path = "src/Image/focuesed_help.png";
                                        pic.repaint();
//                                        //event.playMouse_Over();
                                }
                                if (evt.getKeyCode() == KeyEvent.VK_RIGHT) {
                                        btHelp.requestFocus();
                                        pic.path = "src/Image/focuesed_help.png";
                                        pic.repaint();
//                                        //event.playMouse_Over();
                                }
                        }
                });

                btHelp.addKeyListener(new KeyAdapter() {

                        @Override
                        public void keyPressed(KeyEvent evt) {
                                if (evt.getKeyCode() == KeyEvent.VK_UP) {
                                        btOption.requestFocus();
                                        pic.path = "src/Image/focuesed_option.png";
                                        pic.repaint();
                                        //event.playMouse_Over();
                                }
                                if (evt.getKeyCode() == KeyEvent.VK_LEFT) {
                                        btOption.requestFocus();
                                        pic.path = "src/Image/focuesed_option.png";
                                        pic.repaint();
                                        //event.playMouse_Over();
                                }
                                if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
                                        btExit.requestFocus();
                                        pic.path = "src/Image/focuesed_exit.png";
                                        pic.repaint();
                                        //event.playMouse_Over();
                                }
                                if (evt.getKeyCode() == KeyEvent.VK_RIGHT) {
                                        btExit.requestFocus();
                                        pic.path = "src/Image/focuesed_exit.png";
                                        pic.repaint();
                                        //event.playMouse_Over();
                                }
                        }
                });

                btExit.addKeyListener(new KeyAdapter() {

                        @Override
                        public void keyPressed(KeyEvent evt) {
                                if (evt.getKeyCode() == KeyEvent.VK_UP) {
                                        btHelp.requestFocus();
                                        pic.path = "src/Image/focuesed_help.png";
                                        pic.repaint();
                                        //event.playMouse_Over();
                                }
                                if (evt.getKeyCode() == KeyEvent.VK_LEFT) {
                                        btHelp.requestFocus();
                                        pic.path = "src/Image/focuesed_help.png";
                                        pic.repaint();
                                        //event.playMouse_Over();
                                }
                                if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
                                        btPlayGame.requestFocus();
                                        pic.path = "src/Image/focuesed_playgame.png";
                                        pic.repaint();
                                        //event.playMouse_Over();
                                }
                                if (evt.getKeyCode() == KeyEvent.VK_RIGHT) {
                                        btPlayGame.requestFocus();
                                        pic.path = "src/Image/focuesed_playgame.png";
                                        pic.repaint();
                                        //event.playMouse_Over();
                                }
                        }
                });
        }

        private void picPanelEvent() {
                pic.addMouseMotionListener(new MouseMotionAdapter() {

                        @Override
                        public void mouseMoved(MouseEvent evt) {
                                final int X = evt.getX();
                                final int Y = evt.getY();
                                if ((X >= 116 && X <= 116 + 135) && (Y >= 220 && Y <= 220 + 147)) {
                                        btPlayGame.requestFocus();
                                        pic.path = "src/Image/focuesed_playgame.png";
                                        pic.repaint();
                                }
                                if ((X >= 293 && X <= 293 + 135) && (Y >= 218 && Y <= 218 + 147)) {
                                        btOption.requestFocus();
                                        pic.path = "src/Image/focuesed_Option.png";
                                        pic.repaint();
                                }
                                if ((X >= 457 && X <= 457 + 135) && (Y >= 286 && Y <= 286 + 147)) {
                                        btHelp.requestFocus();
                                        pic.path = "src/Image/focuesed_help.png";
                                        pic.repaint();
                                }
                                if ((X >= 555 && X <= 555 + 135) && (Y >= 444 && Y <= 444 + 147)) {
                                        btExit.requestFocus();
                                        pic.path = "src/Image/focuesed_exit.png";
                                        pic.repaint();

                                }
                        }
                });

                pic.addMouseListener(new MouseAdapter() {

                        @Override
                        public void mousePressed(MouseEvent evt) {
                                final int X = evt.getX();
                                final int Y = evt.getY();
                                if ((X >= 116 && X <= 116 + 135) && (Y >= 220 && Y <= 220 + 147)) {
                                        btPlayGame.requestFocus();
                                        event.playMouse_Preesed();
                                        event.showPlay();

                                }
                                if ((X >= 293 && X <= 293 + 135) && (Y >= 218 && Y <= 218 + 147)) {
                                        btOption.requestFocus();
                                        event.playMouse_Preesed();
                                        event.showOption();

                                }
                                if ((X >= 457 && X <= 457 + 135) && (Y >= 286 && Y <= 286 + 147)) {
                                        btHelp.requestFocus();
                                        event.playMouse_Preesed();
                                        event.showHelp();

                                }
                                if ((X >= 555 && X <= 555 + 135) && (Y >= 444 && Y <= 444 + 147)) {
                                        btExit.requestFocus();
                                        event.playMouse_Preesed();
                                        event.btExit_Event();

                                }
                        }
                });
        }
}
